package com.rabbitmq.exec.work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.exec.utils.RabbitMqUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Scanner;

/**
 * @Description
 * @Author lhj
 * @Date 2024/4/13 16:40
 */
public class Task01 {
    static Logger logger = LoggerFactory.getLogger(Task01.class);
    
    public static final String QUEUE_NAME = "hello";
    
    public static void main(String[] args) throws Exception {
        try (Channel channel = RabbitMqUtils.getChannel()){
            channel.queueDeclare(QUEUE_NAME, true, false, false, null);
            Scanner sc = new Scanner(System.in);
            while (sc.hasNext()) {
                String message = sc.next();
                channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));
                logger.info("消息发送完成, 队列: {}, msg: {}", QUEUE_NAME, message);
            }
        }
    }
    
}
